package com.gpframework.module.order.service.impl;

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gpframework.module.order.mapper.GpOrderNotifyMapper;
import com.gpframework.module.order.domain.GpOrderNotify;
import com.gpframework.module.order.domain.vo.GpOrderNotifyVo;
import com.gpframework.module.order.service.IGpOrderNotifyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * @ClassName GpOrderNotify
 * @Author gpframework
 * @Date 2023-06-28
 * @Version 1.0.0
 * @Description 消息通知Service业务层处理
 */
@Service
public class GpOrderNotifyServiceImpl extends ServiceImpl<GpOrderNotifyMapper, GpOrderNotify> implements IGpOrderNotifyService {

    /**
     * @Description 查询列表返回VO 用于返回给前端的列表接口
     * @Author gpframework
     * @Date 2023-06-28
     * @Param [lqw]
     * @Return List<GpOrderNotifyVo>
     */
    @Override
    public List<GpOrderNotifyVo> listVo(QueryWrapper<GpOrderNotify> lqw) {
        return this.baseMapper.listVo(lqw);
    }

    /**
     * @Description 通过查询详情VO 用于返回给前端的列详情接口
     * @Author gpframework
     * @Date 2023-06-28
     * @Param [id]
     * @Return GpOrderNotifyVo
     */
    @Override
    public GpOrderNotifyVo getVoById(Long id) {
        return this.baseMapper.getVo(id);
    }

    @Override
    @Transactional
    public void sendNotifyByConfigId(Long configId, Long orderId) {
        List<Long> userIds = this.baseMapper.getUserIdsByConfigId(configId);
        GpOrderNotify gpOrderNotify;
        for (Long userId : userIds) {
            gpOrderNotify = new GpOrderNotify();
            gpOrderNotify.setOrderId(orderId);
            gpOrderNotify.setUserId(userId);
            gpOrderNotify.setContent("您好，您有新的订单需要处理，请您前往确认!");
            this.save(gpOrderNotify);
        }
    }
}
